<!DOCTYPE html>
<html>
<head>
{include file="common/head"}

<style type="text/css">
.layui-upload-img {
width: 92px;
    height: 92px;
    margin: 0 10px 10px 0;
}
.upload-img-div {
	position: relative;
	float: left;
}
.upload-img-div:hover a {
    display: block;
}
.upload-icon-del{
    display: none;
    position: absolute;
    left: 0;
	top: 0;
	height: 58px;
	width: 92px;
	text-align: center;
	background-color: #FFFFFF;
	opacity:0.8;
	padding-top: 34px;
}
.upload-icon-del:hover{color: #FF0000;}
.upload-icon-del i{font-size: 24px;}

.layui-form-module .layui-form-label {
    float: none;
    width: auto;
    text-align: left;
    padding: 9px 0px;
}
.layui-form-module .layui-input-block, .layui-form-module .layui-input-inline{
    margin-left: 0px;
}
</style>
</head>

<body style="background-color: #f2f2f2;">
{include file="common/header"}
<div class="layui-container" style="margin-top: 80px;">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
    
      <div class="layui-card">
        <div class="layui-card-header">提问</div>
        <div class="layui-card-body">
        <form class="layui-form layui-form-module" action="{:url('wendasns/question/post')}" method="post" target="_blank">
        
        <div class="layui-form-item">
          <label class="layui-form-label">标题</label>
          <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required|title" autocomplete="off" class="layui-input">
          </div>
        </div>
        
        <div class="layui-form-item">
          <label class="layui-form-label">问题补充</label>
          <div class="layui-input-block">
            <textarea id="wd-textarea" class="layui-hide" name="content" lay-verify="content" data-id=""></textarea>
          </div>
        </div>
        
        <div class="layui-form-item">
          <label class="layui-form-label">分类</label>
          <div class="layui-input-inline">
            <select name="category">
            {volist name="category" id="item"}
              <option value="{$item.id}">{$item.name}</option>
            {/volist}
            </select>
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">标签</label>
          <div class="layui-input-inline">
            <input type="text" name="tags" class="layui-input">
          </div>
          <div class="layui-form-mid layui-word-aux">多个标签用英文逗号，或空格隔开</div>
        </div>

        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="J_ajax_submit_btn" style="margin-right: 10px;">提交</button>
            {if miniapp() neq true}<input type="checkbox" name="anonymous" lay-skin="primary" title="匿名" value="1">{/if}
          </div>
        </div>
        
          </form>
        </div>
      </div>
      
    </div>
    
  </div>
</div>
{include file="common/footer"}
<script src="/ueditor/ueditor.init.js?v={:time()}"></script>
<script>
;!function(){
  var $ = layui.$
  ,form = layui.form
  ,layedit = layui.layedit
  ,upload = layui.upload;

    layedit.set({
      uploadImage: {
        url:'{:url('wendasns/common/upload',['type'=>'question'])}'
      }
      ,height: 250
    });
  
  var index = layedit.build('wd-textarea'); //建立编辑器
  $('#wd-textarea').attr('data-id',index);
  

  form.render();
  
  form.verify({
    title: function(value){
      if(value.length > 49){
        return '标题最多49个字符';
      }
    },
    content: function(value){
      if(value.length > 255){
        return '问题补充最多255个字符';
      }
    }
  });

  form.on('submit(J_ajax_submit_btn)', function(obj){
    	var _form = $(obj.form),action = _form.prop('action'),method = _form.prop('method'),_this = $(this);

    	$.ajax({
    		url: action
    		,type: method
    		,dataType: 'json'
    		,data: obj.field
    		,beforeSend: function(XMLHttpRequest){
    			var textnode = document.createTextNode('\u4e2d\u002e\u002e\u002e');
  	  	  		_this[0].appendChild(textnode);
  	  	  		_this.prop('disabled',true).addClass('layui-btn-disabled');
    		}
    		,complete: function(XMLHttpRequest, textStatus){
    			var org_text = _this.text();
  	  	  	  	_this.text(org_text.replace(/(中...)$/, ''));
  	  	  	  	_this.removeProp('disabled').removeClass('layui-btn-disabled');
  	  	  	}
    		,success: function(res){
    			layer.msg(res.msg,{},function(){
    			  if(res.code==0){
    			    location.href = res.referer;
    			  }
    			});
    		}
    		,error: function(res){
    			layer.msg(res.msg, {icon:2});
    		}
    	});
    return false;
  });
  
  $('body').on('click','.upload-icon-del',function(){
  	$(this).parent().remove();
  });
  
  
}();

</script>
</body>
</html>